package cn.fl.project.controller;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.comm.facade.upload.constant.UploadConstant;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.handler.ResponseFilter;
import cn.fl.preloan.condition.PrjPrdInvoiceQueryCondition;
import cn.fl.project.api.ICheckInvoiceApiService;
import cn.fl.project.api.IPrjPrdExtApiService;
import cn.fl.project.condition.InvoiceInfoQueryCondition;
import cn.fl.project.condition.InvoiceOrCertQueryCondition;
import cn.fl.project.constant.PrjBscInfoConstant;
import cn.fl.project.constant.PrjPrdBscInfoConstant;
import cn.fl.project.constant.PrjPrdVehInfoConstant;
import cn.fl.project.dto.CheckInvoiceResultDTO;
import cn.fl.project.dto.PrjPrdInvoiceDTO;
import cn.fl.project.service.IPrjBscInfoService;
import cn.fl.project.service.IPrjPrdDtlService;
import cn.fl.project.service.IPrjPrdInvoiceService;
import cn.fl.project.service.IPrjPrdVehInfoService;
import cn.fl.project.vo.PrjBscInfoVO;
import cn.fl.project.vo.PrjPrdInvoiceVO;
import cn.fl.system.constant.SysLogConstant;
import cn.fl.system.service.ISysUlDatCfgService;
import cn.fl.system.service.ISysUlFilesRecService;
import cn.fl.system.vo.SysUlFilesRecVO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Description: 机动车发票 控制层
 */
@Controller
@RequestMapping("/project/prjPrdInvoice")
public class PrjPrdInvoiceController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(PrjPrdInvoiceController.class);

	/**
	 * PrjPrdInvoice 服务层BEAN
	 */
	@Autowired
	private IPrjPrdInvoiceService prjPrdInvoiceService;
	/**
	 * PrjPrdVehInfo 服务层BEAN
	 */
	@Autowired
	private IPrjPrdVehInfoService prjPrdVehInfoService;
	@Autowired
	private ICstBscInfoService cstBscInfoService;
	/**
	 * PrjBscInfo 服务层BEAN
	 */
	@Autowired
	private IPrjBscInfoService prjBscInfoService;
	/**
	 * 文件 服务层BEAN
	 */
	@Autowired
	private ISysUlFilesRecService sysUlFilesRecService;
	@Autowired
	private ISysUlDatCfgService sysUlDatCfgService;
	/**
	 * PrjBscInfo 服务层BEAN
	 */
	@Autowired
	private IPrjPrdDtlService prjPrdDtlService;
	@Autowired
	private IPrjPrdExtApiService prjPrdExtApiService;
	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;
	@Autowired
	private ICheckInvoiceApiService checkInvoiceApiService;

	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("project/prjPrdInvoice/prjPrdInvoincelist");
		//事业部
		List<KeyValueVO> buOrgCdList = this.cstBscInfoService.searchBusinessOrgList();
		//项目类型
		List<KeyValueVO> projectTypeList = this.prjBscInfoService.getProjectTypeList();
		//业务类型
		List<KeyValueVO> bizTypeList = this.prjBscInfoService.getBizTypeList();
		List<KeyValueVO> isYesList  = this.cstBscInfoService.searchYNList();
		//GPS审核状态
		List<KeyValueVO> gpsAudStsList = this.prjBscInfoService.getGPSAudStsList();
		//发票审核状态
		List<KeyValueVO> invoiceAudStsList = this.prjBscInfoService.getAudStsList();
		//dtlId
		String dtlId = request.getParameter("dtlId");
		String paySchNo = request.getParameter("paySchNo");
		view.addObject("dtlId", dtlId);
		view.addObject("paySchNo", paySchNo);
		view.addObject("buOrgCdList", buOrgCdList);
		view.addObject("projectTypeList", projectTypeList);
		view.addObject("bizTypeList", bizTypeList);
		view.addObject("isYesList", isYesList);
		view.addObject("gpsAudStsList", gpsAudStsList);
		view.addObject("invoiceAudStsList", invoiceAudStsList);
		BaseLogUtils.info(logger, "toListPage", "跳转到列表页面.", CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 到修改页面
	 */
	@RequestMapping(value = "/toModifyPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		ModelAndView view = new ModelAndView("project/prjPrdInvoice/modify");
		view.addObject("id", id);
		BaseLogUtils.info(logger, "toModifyPage", "跳转到修改页面.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String lsCntNo = request.getParameter("lsCntNo");
		String paySchNo = request.getParameter("paySchNo");
		String cstNm = request.getParameter("cstNm");
		String buOrgCd = request.getParameter("buOrgCd");
		String prjTypCd = request.getParameter("prjTypCd");
		//资料是否上传
		String isUploadFile = request.getParameter("isUploadFile");
		//发票号码
		String invoicenum = request.getParameter("invoicenum");
		//发票审核状态
		String audStsCd = request.getParameter("AudStsCd");
		//dtl关联查询发票标识
		String dtlFlag = request.getParameter("dtlFlag");
		//发票类别
		String flag = request.getParameter("flag");

		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}
		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		PrjPrdInvoiceQueryCondition qc = new PrjPrdInvoiceQueryCondition();
		if (StringUtils.isNotEmpty(lsCntNo)) { 
			qc.setLsCntNo(lsCntNo);
		}
		if (StringUtils.isNotEmpty(paySchNo)) { 
			qc.setPaySchNo(paySchNo);
		}
		if (StringUtils.isNotEmpty(cstNm)) { 
			qc.setCstNm(cstNm);
		}
		if (StringUtils.isNotEmpty(buOrgCd)) { 
			qc.setBuOrgCd(buOrgCd);
		}
		if (StringUtils.isNotEmpty(prjTypCd)) { 
			qc.setPrjTypCd(prjTypCd);
		}
		if (StringUtils.isNotEmpty(isUploadFile)) { 
			qc.setIsUploadFile(Integer.parseInt(isUploadFile));
		}
		if (StringUtils.isNotEmpty(invoicenum)) { 
			qc.setInvoicenum(invoicenum);
		}
		if (StringUtils.isNotEmpty(audStsCd)) {
			qc.setAudStsCd(audStsCd);
		}
		if ("1".equals(dtlFlag)) {
			qc.setDtlIdFlag(true);
			String dtlId = request.getParameter("dtlId");
			if (StringUtils.isNotEmpty(dtlId)) {
				qc.setPrjPrdDtlId(Long.valueOf(dtlId));
			}
		}
		if (StringUtils.isNotEmpty(flag)) {
			qc.setFlag(flag);
		}
		//添加权限
		qc.setUsrId(CurrentThreadContext.getCurrentUserId());	
		page.setCondition(qc);
	
		Pager pager = this.prjPrdInvoiceService.searchListPage(page);
		List<PrjPrdInvoiceVO> list = (List<PrjPrdInvoiceVO>) pager.getResultList();
		ListPageVO<PrjPrdInvoiceVO> listPage = new ListPageVO<PrjPrdInvoiceVO>(list, pager.getTotalCount());
		BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}

	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeById.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			return result;
		}
		try {
			this.prjPrdInvoiceService.removeById(Long.valueOf(id));
			BaseLogUtils.info(logger, "removeById", "删除数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "removeById", "删除数据失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "removeById", "删除数据失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}

		return result;
	}

	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeInvoice.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeInvoice(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String fileId = request.getParameter("fileId");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(fileId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			return result;
		}
		try {
			this.prjPrdInvoiceService.removeInvoice(Long.valueOf(fileId));
			BaseLogUtils.info(logger, "removeById", "删除数据.[id="+fileId+"]", CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "removeById", "删除数据失败.[id="+fileId+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "removeById", "删除数据失败.[id="+fileId+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}

		return result;
	}

	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.error(logger, "getById", "获取数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		
		try {
			PrjPrdInvoiceVO vo = this.prjPrdInvoiceService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
				BaseLogUtils.info(logger, "getById", "获取数据,数据不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			}
			result.setData(vo);
			BaseLogUtils.info(logger, "getById", "获取数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getById", "获取失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "getById", "获取失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}

	/**
	 * 获取数据
	 *
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getPrjPrdInvoiceList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getPrjPrdInvoiceList(HttpServletRequest request) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		//合同号
		String lsCntNo = request.getParameter("lsCntNo");
		//支付表号
		String paySchNo = request.getParameter("paySchNo");
		//产品明细
		String dtlId = request.getParameter("dtlId");
		//查询结果数量
		int total = 0;
		PrjPrdInvoiceQueryCondition qc = new PrjPrdInvoiceQueryCondition();
		if (StringUtils.isNotEmpty(lsCntNo)) {
			qc.setLsCntNo(lsCntNo);
		}
		if (StringUtils.isNotEmpty(paySchNo)) {
			qc.setPaySchNo(paySchNo);
		}
		if (StringUtils.isNotEmpty(dtlId)) {
			qc.setPrjPrdDtlId(Long.valueOf(dtlId));
		}
		try {
			List<PrjPrdInvoiceVO> prjPrdInvoiceList = this.prjPrdInvoiceService.searchPrjPrdInvoiceListByCondition(qc);
			if (CollectionUtils.isNotEmpty(prjPrdInvoiceList)) {
				total = prjPrdInvoiceList.size();
			}
			result.setData(total);
			BaseLogUtils.info(logger, "getById", "获取数据.[paySchNo="+paySchNo+"]", CurrentThreadContext.getCurrentUserName());
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getById", "获取失败.[paySchNo="+paySchNo+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "getById", "获取失败.[paySchNo="+paySchNo+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}

	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do")
	@ResponseBody
	public Object add(PrjPrdInvoiceVO entity,HttpServletRequest request) throws BaseException {
		String invoiceFilePath = request.getParameter("invoiceFilePath");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		if(StringUtils.isEmpty(invoiceFilePath)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("请先上传发票!");
			BaseLogUtils.info(logger, "modify", "新增数据,请先上传发票![invoiceFilePath="+invoiceFilePath+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		try {
			entity.setCrtTm(new Date());
			entity.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			entity.setAudStsCd(PrjPrdVehInfoConstant.PRJ_VEH_AUD_STS_CD_0);
			Long id = this.prjPrdInvoiceService.add(entity);
			result.setData(id);
			BaseLogUtils.info(logger, "add", "新增数据.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modify.do")
	@ResponseBody
	public Object modify(PrjPrdInvoiceVO entity,HttpServletRequest request) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "modify", "修改数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		if(StringUtils.isEmpty(entity.getFileId())){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("请先上传发票!");
			BaseLogUtils.info(logger, "modify", "修改数据,请先上传发票![id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		try {
			//entity = new PrjPrdInvoiceVO();
			entity.setId(Long.valueOf(id));
			entity.setMdfTm(new Date());
			entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
			boolean success = this.prjPrdInvoiceService.modify(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
				BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			}
			BaseLogUtils.info(logger, "modify", "修改成功.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		result.setData(entity.getId());
		return result;
	}

	/**
	 * 到详细页面
	 */
	@RequestMapping(value = "/toDetailPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toDetailPage(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		String detailFlag = request.getParameter("detailFlag");
		String dtlId = request.getParameter("dtlId");//产品明细
		String lsCntNo = request.getParameter("lsCntNo");//合同号
		String prdNm = request.getParameter("prdNm");//租赁物名称
		String cstNm = request.getParameter("cstNm");//客户名称
		//支付表号
		String paySchNo = request.getParameter("paySchNo");
		ModelAndView view = new ModelAndView("project/prjPrdInvoice/prjPrdInvoinceDetail");
		PrjPrdInvoiceVO vehInfo = new PrjPrdInvoiceVO();
		String imgPath="";
		if(StringUtils.isNotBlank(id)){
			vehInfo = 	prjPrdInvoiceService.selectById(Long.valueOf(id));
			//查找上传的发票照片信息
			SysUlFilesRecVO vo=new SysUlFilesRecVO();
			if(StringUtils.isNotBlank(vehInfo.getFileId())) {
				vo=sysUlFilesRecService.selectById(Long.parseLong(vehInfo.getFileId()));
			}
			if(StringUtils.isNotEmpty(vo.getFilePath())) {
				imgPath= vo.getFilePath();
			}
			//查询列表
			PrjPrdInvoiceQueryCondition qc=new PrjPrdInvoiceQueryCondition();
			qc.setId(Long.parseLong(id));
			Pager page=new Pager();
			page.setEveryPage(10000);
			page.setCondition(qc);
			Pager pager = this.prjPrdInvoiceService.searchListPage(page);
			List<PrjPrdInvoiceVO> list = (List<PrjPrdInvoiceVO>) pager.getResultList();//PrjPrdInvoiceVOTransform.toVOList((List<PrjPrdInvoiceDTO>) pager.getResultList());
			if (list!=null&&list.size()>0) {
				PrjPrdInvoiceVO pvo=list.get(0);
				 dtlId = pvo.getDtlId().toString();//产品明细
				 lsCntNo = pvo.getLsCntNo();//合同号
				 prdNm =pvo.getPrdNm();//租赁物名称
				 cstNm =pvo.getCstNm();//客户名称
			}
		}
		if(StringUtils.isNotBlank(cstNm)){//关键字转换 FUJINGRUN
			if(StringUtils.isNotEmpty(cstNm)){
				for (String key : ResponseFilter.keyList) {
					if (cstNm.contains(key)) {
						cstNm = cstNm.replace(key, ResponseFilter.convertKeyMap.get(key));
					}
				}
				vehInfo.setCstNm(cstNm);
			}
		}
		//换车-支付表号查不到
		if (vehInfo != null && StringUtils.isEmpty(vehInfo.getPaySchNo()) && StringUtils.isNotEmpty(paySchNo)) {
			vehInfo.setPaySchNo(paySchNo);
		}
		List<SysDictionaryDTO> listType=sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd() , PrjPrdBscInfoConstant.PRJ_PRD_INVOICE_TYPE_CODE);
		String serverPath = PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_SERVER_PATH);//服务地址
		String customerPah = PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_COSTOMER_PATH);
		String headPic = PropertiesCacheUtils.getProperty(fl.constant.facade.framework.constant.UploadConstant.DEFAULT_NO_PIC);
		view.addObject("id", id==null?"":id);
		view.addObject("vehInfo", vehInfo);
		view.addObject("detailFlag", detailFlag);
		view.addObject("dtlId", dtlId);
		view.addObject("listType", listType);
		view.addObject("filePath", imgPath);//上传发票照片信息
		view.addObject("defImg", serverPath+customerPah+headPic);
		view.addObject("lsCntNo", lsCntNo);
		view.addObject("prdNm", prdNm);
		BaseLogUtils.info(logger, "toDetailPage", "跳转到查看页面.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 跳转到添加发票信息页面
	 * @param 
	 */
	@RequestMapping(value = "/toAddPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toAddPage(HttpServletRequest request, HttpServletResponse response,@RequestParam(required = false,defaultValue = "0") String isGpsNode) {
		ModelAndView view = new ModelAndView("project/prjPrdInvoice/prjPrdInvoinceAdd");
		String dtlId = request.getParameter("dtlId");
		String prjId = request.getParameter("prjId");
		String paySchId = request.getParameter("paySchId");
		String paySchNo = request.getParameter("paySchNo");
		String cstNm = request.getParameter("cstNm");
		String prdNm = request.getParameter("prdNm");
		String lsCntNo = request.getParameter("lsCntNo");
		String flag = request.getParameter("flag");
		String id = request.getParameter("id");
		int invoiceCount = 0;
		PrjPrdInvoiceVO vehInfo = new PrjPrdInvoiceVO();
		//http位置
		String imgPath="";
		//相对位置
		String absLocPath="";
		if(StringUtils.isNotBlank(id)){
			vehInfo = prjPrdInvoiceService.selectById(Long.valueOf(id));
			//查找上传的发票照片信息
			SysUlFilesRecVO vo=new SysUlFilesRecVO();
			if(StringUtils.isNotBlank(vehInfo.getFileId())) {
				vo=sysUlFilesRecService.selectById(Long.parseLong(vehInfo.getFileId()));
			}
			if(StringUtils.isNotEmpty(vo.getFilePath())) {
				imgPath= vo.getFilePath();
				absLocPath=vo.getAbsLocPath();
			}
			//查询列表
			PrjPrdInvoiceQueryCondition qc = new PrjPrdInvoiceQueryCondition();
			qc.setId(Long.parseLong(id));
			Pager page=new Pager();
			page.setEveryPage(10000);
			page.setCondition(qc);
			Pager pager = this.prjPrdInvoiceService.searchListPage(page);
			List<PrjPrdInvoiceVO> list = (List<PrjPrdInvoiceVO>) pager.getResultList();//PrjPrdInvoiceVOTransform.toVOList((List<PrjPrdInvoiceDTO>) pager.getResultList());
			if (list!=null&&list.size()>0) {
				PrjPrdInvoiceVO pvo=list.get(0);
				//产品明细
				 dtlId = pvo.getDtlId().toString();
				//合同号
				 lsCntNo = pvo.getLsCntNo();
				//租赁物名称
				 prdNm =pvo.getPrdNm();
				//客户名称
				 cstNm =pvo.getCstNm();
				 prjId =pvo.getPrjId().toString(); 
				 paySchId =pvo.getPaySchId().toString(); 
				 paySchNo =pvo.getPaySchNo();
				 lsCntNo =pvo.getLsCntNo();
				 isGpsNode = "1";
			}
		}

		//服务地址
		String serverPath = PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_SERVER_PATH);
		String customerPah = PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_COSTOMER_PATH);
		String headPic = PropertiesCacheUtils.getProperty(fl.constant.facade.framework.constant.UploadConstant.DEFAULT_NO_PIC);
		
		//返回jsp属性值

		//上传发票照片信息
		view.addObject("filePath", imgPath);
		view.addObject("defImg", serverPath+customerPah+headPic);
		view.addObject("cfgCd", PrjPrdBscInfoConstant.PRJ_PRD_FILE_INVOICE_CODE);
		// view.addObject("cfgDtlCd", PrjPrdBscInfoConstant.PRJ_PRD_FILE_INVOICE_PHOTO_CODE);
		view.addObject("dtlId",dtlId);
		view.addObject("prjId",prjId);
		view.addObject("paySchId",paySchId);
		view.addObject("paySchNo",paySchNo);
		view.addObject("cstNm",cstNm);
		view.addObject("prdNm",prdNm);
		view.addObject("lsCntNo",lsCntNo);
		view.addObject("flag",flag);
		view.addObject("sysCd",CurrentThreadContext.getCurrentSysCd());
		view.addObject("orgCd", CurrentThreadContext.getCurrentOrgCd());
		view.addObject("buOrgCd", PrjBscInfoConstant.CODE_PRJ_FILE_DEF_ORG);
		view.addObject("vehInfo", vehInfo);
		view.addObject("absLocPath",absLocPath);
		view.addObject("isGpsNode", isGpsNode);
		BaseLogUtils.info(logger, "toAddPage", "跳转到添加发票信息", CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 校验发票号码是否重复
	 */
	@RequestMapping(value = "/checkInvoiceNumRepeat.do", method = { RequestMethod.POST })
	@ResponseBody
	public String checkInvoiceNumRepeat(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		String invoicenum = request.getParameter("invoicenum");
		String invoicecode = request.getParameter("invoicecode");
		String flag = request.getParameter("flag");
		String lsCntNo = request.getParameter("lsCntNo");
		String prjId = request.getParameter("prjId");
		//1校验不重复 2校验重复
		String result="1";
		PrjPrdInvoiceQueryCondition qc = new PrjPrdInvoiceQueryCondition();
		if(StringUtils.isNotBlank(invoicenum)) {
			qc.setInvoicenum(invoicenum);
		}
		if(StringUtils.isNotBlank(invoicecode)){
			qc.setInvoicecode(invoicecode);
		}
		if(StringUtils.isNotBlank(flag) && flag.equals("10")){
			qc.setFlag(flag);
		}
		BaseLogUtils.info(logger, "checkInvoiceNumRepeat", "验证机动车发票信息条件：id="+id+",invoicenum="+invoicenum+",invoicecode="+invoicecode+",flag="+flag+",lsCntNo="+lsCntNo);
		List<PrjPrdInvoiceVO> invoiceVOList = this.prjPrdInvoiceService.searchPrjPrdInvoiceList(qc);
		BaseLogUtils.info(logger, "checkInvoiceNumRepeat", "获取机动车发票信息列表:" + JSONObject.toJSONString(invoiceVOList));
		if(invoiceVOList.size()==0 || invoiceVOList==null) {
			result="1";
			return result;
		}
		if (flag.equals("10")){ //设备发票原件，以支付表维度校验
			if(StringUtils.isNotEmpty(id)) {
				if(invoiceVOList.size()==1) {
					for(PrjPrdInvoiceVO invoiceVO :invoiceVOList) {
						if(id.equals(invoiceVO.getId().toString())) {
							result="1";
							return result;
						}else {
							result="2";
						}
					}
				}else {
					result="2";
				}
			}else {
				if(invoiceVOList.size()>=1) {
					result="2";
				}
			}
		}else { //汽车配件票，以合同维度校验，同一合同内发票号可以重复
			PrjPrdInvoiceVO invoiceVO = invoiceVOList.get(0);
			PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(invoiceVO.getPrjId());
			BaseLogUtils.info(logger, "checkInvoiceNumRepeat", "获取发票表中发票码相同的项目基础信息prjBscInfoVO:" + JSONObject.toJSONString(prjBscInfoVO));
			result = prjBscInfoVO.getLsCntNo().equals(lsCntNo) ? "1" : "2";
		}
		BaseLogUtils.info(logger, "checkInvoiceNumRepeat", "校验成功.[id="+id+"] DATA:" + JSONObject.toJSONString(invoicenum), CurrentThreadContext.getCurrentUserName());
		return result;
	}

	/**
	 * 校验发票类别是否重复
	 */
	@RequestMapping(value = "/checkInvoiceFlagRepeat.do", method = { RequestMethod.POST })
	@ResponseBody
	public String checkInvoiceFlagRepeat(HttpServletRequest request) throws BaseException {
		String paySchNo = request.getParameter("paySchNo");
		String flag = request.getParameter("flag");
		String prjPrdChangeFlag = request.getParameter("prjPrdChangeFlag");
		String dtlId = request.getParameter("dtlId");
		//1校验不重复 2校验重复
		String result="1";

		PrjPrdInvoiceQueryCondition qc = new PrjPrdInvoiceQueryCondition();
		qc.setFlag(flag);
		qc.setPaySchNo(paySchNo);
		if ("true".equals(prjPrdChangeFlag) && StringUtils.isNotEmpty(dtlId)) {
			qc.setPaySchNo(null);
			qc.setPrjPrdDtlId(Long.valueOf(dtlId));
		}

		List<PrjPrdInvoiceVO> prjPrdInvoiceList = this.prjPrdInvoiceService.searchPrjPrdInvoiceListByCondition(qc);

		if(CollectionUtils.isNotEmpty(prjPrdInvoiceList)) {
			if(prjPrdInvoiceList.size() > 0) {
				result = "2";
			}
		}
		BaseLogUtils.info(logger, "checkInvoiceFlagRepeat", "校验成功.[paySchNo="+paySchNo+"] DATA:" + flag, CurrentThreadContext.getCurrentUserName());
		return result;
	}

	/**lxb
	 * 到评审流程信审审核查看列表页面
	 */
	@RequestMapping(value = "/toflowListPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toflowListPage(HttpServletRequest request, HttpServletResponse response) {
		String paySchNo = request.getParameter("paySchNo");
		ModelAndView view = new ModelAndView("project/prjPrdInvoice/prjPrdInvoinceFlowList");
		String isAllowPay = request.getParameter("isAllowPay");
		view.addObject("paySchNo", paySchNo);
		view.addObject("isAllowPay",isAllowPay);
		BaseLogUtils.info(logger, "toflowListPage", "到评审流程信审审核查看列表页面.[paySchNo="+paySchNo+"]", CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**lxb
	 * 初始化列表
	 * 评审流程信审审核查看列表页面
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initflowList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initflowList(HttpServletRequest request, HttpServletResponse response) {
		
		String paySchNo = request.getParameter("paySchNo");
		PrjPrdInvoiceQueryCondition inqc = new PrjPrdInvoiceQueryCondition();
		
		//TODO SOMETHING
		if (StringUtils.isNotEmpty(paySchNo)) {
			BaseLogUtils.info(logger, "initflowList", "查询数据主键id是空", CurrentThreadContext.getCurrentUserName());
			inqc.setPaySchNo(paySchNo);
		}else{
			return null;
		}
		//发票
		List<PrjPrdInvoiceVO> list = (List<PrjPrdInvoiceVO>) this.prjPrdInvoiceService.searchListForXS(inqc);
		if (list!=null&&list.size()>0) {
			PrjPrdInvoiceVO lastVO=new PrjPrdInvoiceVO();
			lastVO.setTotLsItmAmt(list.get(0).getTotLsItmAmt());
			double all=0.0;
			for (PrjPrdInvoiceVO vo:list) {
				if (vo.getPricetax()!=null) {
					all+=vo.getPricetax().doubleValue();
				}
				vo.setTotLsItmAmt(null);
			}
			lastVO.setVinnumck("合计:");
			lastVO.setPricetax(all);
			list.add(lastVO);
		}
		
		
		ListPageVO<PrjPrdInvoiceVO> listPage = new ListPageVO<PrjPrdInvoiceVO>(list, list.size());
		BaseLogUtils.info(logger, "initflowList", "查询数据完成. DATA:" + JSONObject.toJSONString(list), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}
	/**
	 * 上传发票照片
	 */
	@RequestMapping(value = "/addProjectInvoicePhoto.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object addProjectInvoicePhoto(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		String fileParams = request.getParameter("fileList");
		String old_file_id = request.getParameter("old_file_id");
		String serverPrefixPath = PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_SERVER_PATH);
		//新增文件记录id
		Long id = null;
		List<SysUlFilesRecVO> fileList = new ArrayList<SysUlFilesRecVO>();
		try {
			if (StringUtils.isNotBlank(fileParams)) {
				fileList = JSON.parseArray(fileParams, SysUlFilesRecVO.class);
			}
			if(CollectionUtils.isNotEmpty(fileList)){
				for (SysUlFilesRecVO sysUlFilesRecVO : fileList) {
					sysUlFilesRecVO.setTabNm("PRJ_PRD_INVOICE");
					sysUlFilesRecVO.setCrtTm(new Date());
					sysUlFilesRecVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
					sysUlFilesRecVO.setMdfTm(new Date());
					sysUlFilesRecVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
					sysUlFilesRecVO.setIsDel(BaseConstant.IS_YESNO_NO);
					sysUlFilesRecVO.setAbsLocPath(PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_ROOT_PATH)+sysUlFilesRecVO.getFilePath().replace(serverPrefixPath,""));
					id=sysUlFilesRecService.add(sysUlFilesRecVO);
					sysUlFilesRecVO.setId(id);
				}
				result.setData(fileList.get(0));
			}
			
			if(StringUtils.isNotBlank(old_file_id)) {
				//根据上传文件的ID删掉之前旧的文件
				List<Long> ids=new ArrayList<Long>();
				ids.add(Long.parseLong(old_file_id));
				sysUlFilesRecService.removeByIds(ids);
			}
			BaseLogUtils.info(logger, "add", "新增数据.[id="+id+"] DATA:" + JSONObject.toJSONString(fileParams), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(fileParams) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(fileParams) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}

	/**
	 * 获取发票信息照片
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getPrjPrdInvoiceImg.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object getPrjPrdInvoiceImg(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String fileId = request.getParameter("fileId");//上传发票信息照片
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		try {
			List<SysUlFilesRecVO> list = new ArrayList<SysUlFilesRecVO>();;
			SysUlFilesRecVO fileVo=sysUlFilesRecService.selectById(Long.parseLong(fileId));
			list.add(fileVo);
			result.setData(list);
			BaseLogUtils.info(logger, "getPrjPrdVehImgList", "解析数据失败!", CurrentThreadContext.getCurrentUserName());
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getPrjPrdVehImgList", "获取失败.[id=]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "getPrjPrdVehImgList", "获取失败.[id=]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	/**
	 *  ocr识别
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getPrjPrdInvoiceOcr.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object getPrjPrdInvoiceOcr(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		//上传发票信息照片路径
		String filePath = request.getParameter("filePath");
		//OCR识别图片类型
		String type = request.getParameter("type");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "识别成功");
		CheckInvoiceResultDTO checkInvoiceResultDTO=new CheckInvoiceResultDTO();
		PrjPrdInvoiceDTO vehInfo =new PrjPrdInvoiceDTO();
		try {
			BaseLogUtils.info(logger, "getPrjPrdInvoiceOcr", "imgFilePath"+filePath, CurrentThreadContext.getCurrentUserName());
			InvoiceOrCertQueryCondition invoiceOrCertQueryCondition = new InvoiceOrCertQueryCondition();
			invoiceOrCertQueryCondition.setImgPath(filePath);
			invoiceOrCertQueryCondition.setType(type);
			checkInvoiceResultDTO = this.checkInvoiceApiService.getInvoiceOrCertByOCR(invoiceOrCertQueryCondition);
			if(checkInvoiceResultDTO.getSuccess()) {
				vehInfo= checkInvoiceResultDTO.getPrjPrdInvoiceDTO();
			}
			result.setData(checkInvoiceResultDTO);
			BaseLogUtils.info(logger, "getPrjPrdInvoiceOcr", JSONObject.toJSONString(checkInvoiceResultDTO) , CurrentThreadContext.getCurrentUserName());
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.error(logger, "getPrjPrdInvoiceOcr", "ocr失败.[checkInvoiceResultDTO=]"+JSONObject.toJSONString(checkInvoiceResultDTO)+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "getPrjPrdInvoiceOcr", "ocr失败.[checkInvoiceResultDTO=]"+JSONObject.toJSONString(checkInvoiceResultDTO)+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	/**
	 * 数据宝接口调用
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getPrjPrdInvoiceDataPay.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object getPrjPrdInvoiceDataPay(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		String invCode = request.getParameter("invCode");//发票代码
		String invNo = request.getParameter("invNo");//发票号码
		String invTime = request.getParameter("invTime");//开票日期，格式：20190416
		String invOther = request.getParameter("invOther");//不含税金额(发票类型为专票时，填写未税金额；发票类型为二手车时，填写发票车价合计),格式： 60300.00
		String checkCode =request.getParameter("checkCode");//校验码(校验码后六位（发票类型为普票、电子票时不可为空）)
		CheckInvoiceResultDTO checkInvoiceResultDTO=new CheckInvoiceResultDTO() ;
		try {
			InvoiceInfoQueryCondition invoiceInfoQueryCondition = new InvoiceInfoQueryCondition();
	    	invoiceInfoQueryCondition.setInvCode(invCode);//发票代码
	    	invoiceInfoQueryCondition.setInvNo(invNo);//发票号码
	    	invoiceInfoQueryCondition.setInvTime(invTime);//开票日期
	    	invoiceInfoQueryCondition.setInvOther(invOther);//不含税金额(发票类型为专票时，填写未税金额；发票类型为二手车时，填写发票车价合计)
	    	invoiceInfoQueryCondition.setCheckCode(checkCode);//校验码(校验码后六位（发票类型为普票、电子票时不可为空）)
	    	checkInvoiceResultDTO = checkInvoiceApiService.getInvoiceInfo(invoiceInfoQueryCondition);
	    	result.setData(checkInvoiceResultDTO);
	    	BaseLogUtils.info(logger, "getPrjPrdInvoiceDataPay", JSONObject.toJSONString(checkInvoiceResultDTO) , CurrentThreadContext.getCurrentUserName());
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.error(logger, "getPrjPrdInvoiceDataPay", "datapay失败.[checkInvoiceResultDTO=]"+JSONObject.toJSONString(checkInvoiceResultDTO)+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "getPrjPrdInvoiceDataPay", "datapay失败.[checkInvoiceResultDTO=]"+JSONObject.toJSONString(checkInvoiceResultDTO)+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}

	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPageHC.do", method = { RequestMethod.GET})
	public ModelAndView toListPageHC(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("project/prjPrdInvoice/prjPrdInvoincelistHC");
		//事业部
		List<KeyValueVO> buOrgCdList = this.cstBscInfoService.searchBusinessOrgList();
		//项目类型
		List<KeyValueVO> projectTypeList = this.prjBscInfoService.getProjectTypeList();
		//业务类型
		List<KeyValueVO> bizTypeList = this.prjBscInfoService.getBizTypeList();
		List<KeyValueVO> isYesList  = this.cstBscInfoService.searchYNList();
		//GPS审核状态
		List<KeyValueVO> gpsAudStsList = this.prjBscInfoService.getGPSAudStsList();
		//发票审核状态
		List<KeyValueVO> invoiceAudStsList = this.prjBscInfoService.getAudStsList();
		//dtlId
		String dtlId = request.getParameter("dtlId");
		String paySchNo = request.getParameter("paySchNo");
		String paySchId = request.getParameter("paySchId");
		String detailFlag = request.getParameter("detailFlag");
		String noPassFlag = request.getParameter("noPassFlag");
		view.addObject("dtlId", dtlId);
		view.addObject("paySchNo", paySchNo);
		view.addObject("paySchId", paySchId);
		view.addObject("detailFlag", detailFlag);
		view.addObject("noPassFlag", noPassFlag);
		view.addObject("buOrgCdList", buOrgCdList);
		view.addObject("projectTypeList", projectTypeList);
		view.addObject("bizTypeList", bizTypeList);
		view.addObject("isYesList", isYesList);
		view.addObject("gpsAudStsList", gpsAudStsList);
		view.addObject("invoiceAudStsList", invoiceAudStsList);
		BaseLogUtils.info(logger, "toListPageHC", "跳转到列表页面.", CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 跳转到添加发票信息页面
	 * @param
	 */
	@RequestMapping(value = "/toAddPageHC.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toAddPageHC(HttpServletRequest request, HttpServletResponse response, @RequestParam(required = false, defaultValue = "0") String isGpsNode) {
		ModelAndView view = new ModelAndView("project/prjPrdInvoice/prjPrdInvoinceAdd");
		String dtlId = request.getParameter("dtlId");
		String prjId = request.getParameter("prjId");
		String paySchId = request.getParameter("paySchId");
		String paySchNo = request.getParameter("paySchNo");
		String cstNm = request.getParameter("cstNm");
		String prdNm = request.getParameter("prdNm");
		String lsCntNo = request.getParameter("lsCntNo");
		String flag = request.getParameter("flag");
		String id = request.getParameter("id");
		//换车标志
		String prjPrdChangeFlag = request.getParameter("prjPrdChangeFlag");
		PrjPrdInvoiceVO vehInfo = new PrjPrdInvoiceVO();
		//http位置
		String imgPath = "";
		//相对位置
		String absLocPath = "";
		if (StringUtils.isNotBlank(id)) {
			vehInfo = prjPrdInvoiceService.selectById(Long.valueOf(id));
			//查找上传的发票照片信息
			SysUlFilesRecVO vo = new SysUlFilesRecVO();
			if (StringUtils.isNotBlank(vehInfo.getFileId())) {
				vo = sysUlFilesRecService.selectById(Long.parseLong(vehInfo.getFileId()));
			}
			if (StringUtils.isNotEmpty(vo.getFilePath())) {
				imgPath = vo.getFilePath();
				absLocPath = vo.getAbsLocPath();
			}
			//查询列表
			PrjPrdInvoiceQueryCondition qc = new PrjPrdInvoiceQueryCondition();
			qc.setId(Long.parseLong(id));
			qc.setDtlIdFlag(true);
			Pager page = new Pager();
			page.setEveryPage(10000);
			page.setCondition(qc);
			Pager pager = this.prjPrdInvoiceService.searchListPage(page);
			List<PrjPrdInvoiceVO> list = (List<PrjPrdInvoiceVO>) pager.getResultList();
			if (list != null && list.size() > 0) {
				PrjPrdInvoiceVO pvo = list.get(0);
				//产品明细
				dtlId = pvo.getDtlId().toString();
				if (StringUtils.isNotEmpty(pvo.getLsCntNo())) {
					//合同号
					lsCntNo = pvo.getLsCntNo();
				}
				if (StringUtils.isNotEmpty(pvo.getPrdNm())) {
					//租赁物名称
					prdNm = pvo.getPrdNm();
				}
				if (StringUtils.isNotEmpty(pvo.getCstNm())) {
					//客户名称
					cstNm = pvo.getCstNm();
				}
				if (pvo.getPrjId() != null) {
					prjId = pvo.getPrjId().toString();
				}
				if (pvo.getPaySchId() != null) {
					paySchId = pvo.getPaySchId().toString();
				}
				if (StringUtils.isNotEmpty(pvo.getPaySchNo())) {
					paySchNo = pvo.getPaySchNo();
				}
				isGpsNode = "1";
			}
		}
		if (StringUtils.isEmpty(lsCntNo) && StringUtils.isNotEmpty(prjId)) {
			//查询项目表
			PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(Long.valueOf(prjId));
			lsCntNo = prjBscInfoVO.getLsCntNo();
			cstNm = prjBscInfoVO.getCstNm();
		}

		//服务地址
		String serverPath = PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_SERVER_PATH);
		String customerPah = PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_COSTOMER_PATH);
		String headPic = PropertiesCacheUtils.getProperty(fl.constant.facade.framework.constant.UploadConstant.DEFAULT_NO_PIC);

		//上传发票照片信息
		view.addObject("filePath", imgPath);
		view.addObject("defImg", serverPath + customerPah + headPic);
		view.addObject("cfgCd", PrjPrdBscInfoConstant.PRJ_PRD_FILE_INVOICE_CODE);
		view.addObject("dtlId", dtlId);
		view.addObject("prjId", prjId);
		view.addObject("paySchId", paySchId);
		view.addObject("paySchNo", paySchNo);
		view.addObject("cstNm", cstNm);
		view.addObject("prdNm", prdNm);
		view.addObject("lsCntNo", lsCntNo);
		view.addObject("flag", flag);
		view.addObject("sysCd", CurrentThreadContext.getCurrentSysCd());
		view.addObject("orgCd", CurrentThreadContext.getCurrentOrgCd());
		view.addObject("buOrgCd", PrjBscInfoConstant.CODE_PRJ_FILE_DEF_ORG);
		view.addObject("vehInfo", vehInfo);
		view.addObject("absLocPath", absLocPath);
		view.addObject("isGpsNode", isGpsNode);
		view.addObject("prjPrdChangeFlag", prjPrdChangeFlag);
		BaseLogUtils.info(logger, "toAddPageHC", "跳转到添加发票信息", CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initListHC.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initListHC(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String paySchNo = request.getParameter("paySchNo");
		String paySchId = request.getParameter("paySchId");
		//dtl关联查询发票
		String dtlId = request.getParameter("dtlId");
		String noPassFlag = request.getParameter("noPassFlag");

		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}
		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		PrjPrdInvoiceQueryCondition qc = new PrjPrdInvoiceQueryCondition();
		qc.setDtlIdFlag(true);
		if (StringUtils.isNotEmpty(dtlId)) {
			qc.setPrjPrdDtlId(Long.valueOf(dtlId));
		}
		//换车流程不通过时，查看已删除发票信息
		if (StringUtils.isNotEmpty(noPassFlag) && "true".equals(noPassFlag)) {
			qc.setIsDel(0);
		}
		//添加权限
		qc.setUsrId(CurrentThreadContext.getCurrentUserId());
		page.setCondition(qc);

		Pager pager = this.prjPrdInvoiceService.searchListPage(page);
		List<PrjPrdInvoiceVO> list = (List<PrjPrdInvoiceVO>) pager.getResultList();
		//换车-开始时sql查不到我司支付表号，手动放
		if (CollectionUtils.isNotEmpty(list)) {
			for (PrjPrdInvoiceVO vo : list) {
				if (StringUtils.isEmpty(vo.getPaySchNo())) {
					vo.setPaySchNo(paySchNo);
				}
				if (StringUtils.isEmpty(vo.getPaySchId()) && StringUtils.isNotEmpty(paySchId)) {
					vo.setPaySchId(Long.valueOf(paySchId));
				}
			}
		}
		ListPageVO<PrjPrdInvoiceVO> listPage = new ListPageVO<>(list, pager.getTotalCount());
		BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}

	/**
	 * 新增
	 */
	@RequestMapping(value = "/addByHC.do")
	@ResponseBody
	public Object addByHC(PrjPrdInvoiceVO entity,HttpServletRequest request) throws BaseException {
		String invoiceFilePath = request.getParameter("invoiceFilePath");
		String dtlId = request.getParameter("dtlId");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		if(StringUtils.isEmpty(invoiceFilePath)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("请先上传发票!");
			BaseLogUtils.info(logger, "modify", "新增数据,请先上传发票![invoiceFilePath="+invoiceFilePath+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		try {
			entity.setPrjId(null);
			entity.setPaySchNo(null);
			entity.setPaySchId(null);
			if (StringUtils.isNotEmpty(dtlId)) {
				entity.setPrjPrdDtlId(Long.valueOf(dtlId));
			}
			entity.setCrtTm(new Date());
			entity.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			entity.setAudStsCd(PrjPrdVehInfoConstant.PRJ_VEH_AUD_STS_CD_0);
			Long id = this.prjPrdInvoiceService.add(entity);
			result.setData(id);
			BaseLogUtils.info(logger, "add", "新增数据.[id=" + id + "] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modifyByHC.do")
	@ResponseBody
	public Object modifyByHC(PrjPrdInvoiceVO entity,HttpServletRequest request) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "modify", "修改数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		if(StringUtils.isEmpty(entity.getFileId())){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("请先上传发票!");
			BaseLogUtils.info(logger, "modify", "修改数据,请先上传发票![id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		try {
			entity.setPrjId(null);
			entity.setPaySchNo(null);
			entity.setPaySchId(null);
			entity.setId(Long.valueOf(id));
			entity.setMdfTm(new Date());
			entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
			boolean success = this.prjPrdInvoiceService.modify(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
				BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			}
			BaseLogUtils.info(logger, "modify", "修改成功.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		result.setData(entity.getId());
		return result;
	}
}

